home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
c
/
cube_v1.zip
/
CUBE1.C
< prev
next >
Wrap
Text File
|
1993-06-13
|
27KB
|
979 lines
/*******************************************************************
* CUBE1.C by Hubert Lin & Andrew Lee *
* Mechanical Eng. of National Central University *
* Started 4-27-1993 *
* Finished 6-15-1993 *
* Copyright(C) 1993 All Rights Reserved *
*******************************************************************/
#define VERSION "Version 1.0"
#define F 0 /* Front face */
#define R 1 /* Right face */
#define T 2 /* Top face */
#define H 3 /* Bottom face */
#define L 4 /* Left face */
#define B 5 /* beHind face */
#define RR 0 /* Red */
#define OO 1 /* Orange */
#define GG 2 /* Green */
#define BB 3 /* Blue */
#define YY 4 /* Yellow */
#define WW 5 /* White */
#define SRIMN 8 /* number of small_rim */
#define BRIMN 12 /* number of big_rim */
#define CW -1 /* clockwise */
#define CCW -2 /* counterclockwise */
#define ESC 27 /* key code of Esc */
#define F1 59
#define F2 60
#define F3 61
#define F4 62
#define F5 63
#define F6 64
#define ON 1
#define OFF 0
#include <dos.h>
#include <alloc.h>
#include <ctype.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <graphics.h>
#include "mouse.h"
void body( char );
char getmousech( MOUSE * );
void to_graphic_mode( void );
void initialize( void );
void handle( char );
void faceCW( char );
void faceCCW( char );
int cond( char );
void reassignfacestruct( char );
void showcube( void );
void cube_rotate( char , int );
void savegame( void );
void loadgame( void );
void soundswitch( void );
void speedswitch( void );
void word( void );
void title( void );
void draw_win( void );
void sink( int , int , int , int , int );
void mem_error( void );
void file_error( char * );
void show_version( int , int , int );
void palette( int );
void shell( void );
void clr_kb_buff( void );
void sinkkey( char );
void help( void );
void message( int , char * );
void cubesound( void );
int first=0; /* check if it is first time to draw the cube */
int speed=30; /* the rotation speed of the cube */
int speeddata[] = {10, 30, 50};
/* they are "Fast", "Normal", and "Slow". */
int speedcontrol = 1; /* the controler of speeddata[] */
MOUSE mouse; /* the structure of the cursor of the mouse */
int soundflag = ON; /* the flag of sound ON or OFF */
int mu_install =OFF; /* the flag of use_mouse or not_use_mouse */
int sq[49]; /* the color of the 48 squares, begins at sq[1] */
int condition[] = {RR, BB, YY, OO, GG, WW};
/* they are F, R, T, H, L, B ,respectively*/
int now=0, next=0;
int color[] ={ GREEN , LIGHTRED , RED , DARKGRAY , LIGHTGRAY , WHITE };
/* RED , BROWN , GREEN , BLUE , YELLOW , WHITE */
/* the structure of the 6 faces */
struct one_face
{
int *srim[SRIMN+1]; /* begins at srim[1] */
int *brim[BRIMN+1]; /* begins at brim[1] */
} face[] =
{
{ NULL , &sq[1] , &sq[2] , &sq[3] , &sq[4] , &sq[5] , &sq[6] ,
&sq[7] , &sq[8] , NULL , &sq[39] , &sq[38] , &sq[37] , &sq[25] ,
&sq[32] , &sq[31] , &sq[47] , &sq[46] , &sq[45] , &sq[21] , &sq[20] ,
&sq[19] } ,
{ NULL , &sq[9] , &sq[10] , &sq[11] , &sq[12] , &sq[13] , &sq[14] ,
&sq[15] , &sq[16] , NULL , &sq[35] , &sq[34] , &sq[33] , &sq[17] ,
&sq[24] , &sq[23] , &sq[43] , &sq[42] , &sq[41] , &sq[29] , &sq[28] ,
&sq[27] } ,
{ NULL , &sq[17] , &sq[18] , &sq[19] , &sq[20] , &sq[21] , &sq[22] ,
&sq[23] , &sq[24] , NULL , &sq[33] , &sq[40] , &sq[39] , &sq[1] ,
&sq[8] , &sq[7] , &sq[45] , &sq[44] , &sq[43] , &sq[13] , &sq[12] ,
&sq[11] } ,
{ NULL , &sq[25] , &sq[26] , &sq[27] , &sq[28] , &sq[29] , &sq[30] ,
&sq[31] , &sq[32] , NULL , &sq[37] , &sq[36] , &sq[35] , &sq[9] ,
&sq[16] , &sq[15] , &sq[41] , &sq[48] , &sq[47] , &sq[5] , &sq[4] ,
&sq[3] } ,
{ NULL , &sq[33] , &sq[34] , &sq[35] , &sq[36] , &sq[37] , &sq[38] ,
&sq[39] , &sq[40] , NULL , &sq[11] , &sq[10] , &sq[9] , &sq[27] ,
&sq[26] , &sq[25] , &sq[3] , &sq[2] , &sq[1] , &sq[19] , &sq[18] ,
&sq[17] } ,
{ NULL , &sq[41] , &sq[42] , &sq[43] , &sq[44] , &sq[45] , &sq[46] ,
&sq[47] , &sq[48] , NULL , &sq[15] , &sq[14] , &sq[13] , &sq[23] ,
&sq[22] , &sq[21] , &sq[7] , &sq[6] , &sq[5] , &sq[31] , &sq[30] ,
&sq[29] }
};
struct condition_data
{
int face[6]; /* face F , R , T , H , L , B */
int lefttop[3]; /* face F , R , T */
int cw[3][2]; /* rotate about x , y , z */
int ccw[3][2]; /* rotate about x , y , z */
} conddata[] =
{
{RR,BB,YY,OO,GG,WW, 1,1,1, WW,BB, RR,YY, BB,OO, YY,BB, RR,WW, GG,RR},
{RR,WW,BB,OO,YY,GG, 3,7,3, GG,WW, RR,BB, WW,OO, BB,WW, RR,GG, YY,RR},
{RR,GG,WW,OO,BB,YY, 5,5,1, YY,GG, RR,WW, GG,OO, WW,GG, RR,YY, BB,RR},
{RR,YY,GG,OO,WW,BB, 7,7,7, BB,YY, RR,GG, YY,OO, GG,YY, RR,BB, WW,RR},
{OO,GG,YY,RR,BB,WW, 1,1,5, WW,GG, OO,YY, GG,RR, YY,GG, OO,WW, BB,OO},
{OO,WW,GG,RR,YY,BB, 3,3,3, BB,WW, OO,GG, WW,RR, GG,WW, OO,BB, YY,OO},
{OO,BB,WW,RR,GG,YY, 5,5,5, YY,BB, OO,WW, BB,RR, WW,BB, OO,YY, GG,OO},
{OO,YY,BB,RR,WW,GG, 7,3,7, GG,YY, OO,BB, YY,RR, BB,YY, OO,GG, WW,OO},
{GG,YY,OO,BB,WW,RR, 7,1,7, RR,YY, GG,OO, YY,BB, OO,YY, GG,RR, WW,GG},
{GG,RR,YY,BB,OO,WW, 1,1,3, WW,RR, GG,YY, RR,BB, YY,RR, GG,WW, OO,GG},
{GG,WW,RR,BB,YY,OO, 3,5,3, OO,WW, GG,RR, WW,BB, RR,WW, GG,OO, YY,GG},
{GG,OO,WW,BB,RR,YY, 5,5,7, YY,OO, GG,WW, OO,BB, WW,OO, GG,YY, RR,GG},
{BB,OO,YY,GG,RR,WW, 1,1,7, WW,OO, BB,YY, OO,GG, YY,OO, BB,WW, RR,BB},
{BB,WW,OO,GG,YY,RR, 3,1,3, RR,WW, BB,OO, WW,GG, OO,WW, BB,RR, YY,BB},
{BB,RR,WW,GG,OO,YY, 5,5,3, YY,RR, BB,WW, RR,GG, WW,RR, BB,YY, OO,BB},
{BB,YY,RR,GG,WW,OO, 7,5,7, OO,YY, BB,RR, YY,GG, OO,YY, BB,OO, WW,BB},
{YY,BB,OO,WW,GG,RR, 1,3,5, RR,BB, YY,OO, BB,WW, OO,BB, YY,RR, GG,YY},
{YY,RR,BB,WW,OO,GG, 3,3,5, GG,RR, YY,BB, RR,WW, BB,RR, YY,GG, OO,YY},
{YY,GG,RR,WW,BB,OO, 5,3,5, OO,GG, YY,RR, GG,WW, RR,GG, YY,OO, BB,YY},
{YY,OO,GG,WW,RR,BB, 7,3,5, BB,OO, YY,GG, OO,WW, GG,OO, YY,BB, RR,YY},
{WW,GG,OO,YY,BB,RR, 1,7,1, RR,GG, WW,OO, GG,YY, OO,GG, WW,RR, BB,WW},
{WW,RR,GG,YY,OO,BB, 3,7,1, BB,RR, WW,GG, RR,YY, GG,RR, WW,BB, OO,WW},
{WW,BB,RR,YY,GG,OO, 5,7,1, OO,BB, WW,RR, BB,YY, RR,BB, WW,OO, GG,WW},
{WW,OO,BB,YY,RR,GG, 7,7,1, GG,OO, WW,BB, OO,YY, BB,OO, WW,GG, RR,WW}
};
/* the initial color of the 3 visible faces ( Front, Right, Top ) */
struct vfacedata
{
int color[8];
} vface[] =
{
{ GREEN , GREEN , GREEN , GREEN , GREEN , GREEN , GREEN , GREEN } ,
{ DARKGRAY , DARKGRAY , DARKGRAY , DARKGRAY , DARKGRAY , DARKGRAY ,
DARKGRAY , DARKGRAY } ,
{ LIGHTGRAY , LIGHTGRAY , LIGHTGRAY , LIGHTGRAY , LIGHTGRAY , LIGHTGRAY ,
LIGHTGRAY , LIGHTGRAY }
};
/* defines the mouse clickable areas and the corresponding keys */
struct mu_click
{
int cl, ct, cr, cb; /* left, top, right, bottom points of the area */
char key; /* the corresponding keys of the area */
} def_click[]=
{
{ 18+(65+1)*0 , 253 , 18+(65+1)*0+64 , 253+44 , 'f' },
{ 18+(65+1)*1 , 253 , 18+(65+1)*1+64 , 253+44 , 'r' },
{ 18+(65+1)*2 , 253 , 18+(65+1)*2+64 , 253+44 , 't' },
{ 18+(65+1)*3 , 253 , 18+(65+1)*3+64 , 253+44 , 'l' },
{ 18+(65+1)*4 , 253 , 18+(65+1)*4+64 , 253+44 , 'b' },
{ 18+(65+1)*5 , 253 , 18+(65+1)*5+64 , 253+44 , 'h' },
{ 426+(65+1)*0 , 253 , 426+(65+1)*0+64 , 253+44 , 'x' },
{ 426+(65+1)*1 , 253 , 426+(65+1)*1+64 , 253+44 , 'z' },
{ 426+(65+1)*2 , 253 , 426+(65+1)*2+64 , 253+44 , 'y' }